package org.xdq.springcloud.demo20191222.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.xdq.exception.BusinessException;
import org.xdq.exception.SysException;
import org.xdq.model.User;
import org.xdq.springcloud.demo20191222.dao.LoginDao;
import org.xdq.springcloud.demo20191222.service.LoginService;
import org.xdq.base.CurrUser;
import org.xdq.dto.UserDto;
@Service
@Transactional
public class LoginServiceImpl implements LoginService {

	@Autowired
	private LoginDao loginDao;

	

	public CurrUser checkLogin(UserDto dto) {
		User user;
		try {
			user = loginDao.findUserByIdAndPwd(dto);
		} catch (Exception e) {
			throw new SysException("系统错误！",e);
		}
		if(user==null) {
			throw new BusinessException("帐号或密码错误！");
		}
		return new CurrUser(user.getU_id(),user.getU_name());
	}
}
